package com.supreme.studyserver.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class SupremeProxy {

    private final Object target;

    public SupremeProxy(Object target) {
        this.target = target;
    }

    public Object getProxyInstance() {
        Class<?> targetClazz = this.target.getClass();
        return Proxy.newProxyInstance(targetClazz.getClassLoader(), targetClazz.getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("SupremeProxy start");
                Object returnValue = method.invoke(target, args);
                System.out.println("SupremeProxy finish");
                return returnValue;
            }
        });
    }
}
